package com.yu1996.gulimall.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * spring-session的配置类
 * @auther yu
 * @date 2022/1/12
 */
@Configuration
public class GulimallSessionConfig {

  /**
   * 自定义cookied   改变name，作用域等
   * 用于解决子域session共享问题
   * @return
   */
  @Bean
  public CookieSerializer cookieSerializer() {
    DefaultCookieSerializer serializer = new DefaultCookieSerializer();
    serializer.setCookieName("GULI_SESSION");
    serializer.setDomainName("gulimall.com");
    return serializer;
  }

  @Bean
  public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
    return new GenericJackson2JsonRedisSerializer();
  }
}
